package dp;

import java.util.*;


public class lc941 {
    public static void main(String[] args) {
//        System.out.println(validMountainArray(new int[]{1,7,9,5,4,1,2}));
        System.out.println(uniqueOccurrences(new int[]{1,2,2,1,3}));
    }
    public static boolean validMountainArray(int[] arr) {
        int n = arr.length;
        if(n < 3)
            return false;
        /*
        双指针，笨死了
         */
        int l = 0, r = n - 1;
        while(l < n - 1 && arr[l] < arr[l + 1])
            l++;
        while(r > 0 && arr[r] < arr[r - 1])
            r--;
        if(l != n - 1 && r != 0 && l == r)
            return true;
        return false;
    }

    public static boolean uniqueOccurrences(int[] arr) {
        int n = arr.length;
        Set<Integer> set = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        Arrays.sort(arr);
        for (int i = 0; i < n; i++) {
            set2.add(arr[i]);
            int t = 1;
            while(i + 1 < n && arr[i] == arr[i + 1]){
                i++;
                t++;
            }
            set.add(t);
        }
        return set.size() == set2.size();
    }
}
